{extend name="layout/main"}
{block name='title'}会员管理{/block}

{block name='main'}
<div class="container-fluid cm-container-white">
    <h3 style="margin:0">会员管理
        <div class="nav nabbar-nav" role="navigation">
            <div>
                <form action="{:url('admin/user/index')}" method="get" class="navbar-form navbar-right" role="search">
                    <div class="form-group">
                        <input type="text" class="form-control" name="name" placeholder="请输入用户名"/>
                    </div>
                    <button type="submit" class="btn btn-default">提交</button>
                </form>
            </div>
        </div>
        <button class="btn btn-success pull-right" id="addUser" data-toggle="tooltip" title="新增会员" type="button">
            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
        </button>
    </h3>
    <div class="table-responsive">
        <table class="table table-hover">
            <thead>
            <tr class="row">
                <th>id</th>
                <th>名字</th>
                <th>电话号码</th>
                <th>性别</th>
                <th>用户类别</th>
                <th class="col-sm-4">操作</th>
            </tr>
            </thead>
            <tbody>
            {foreach $data as $d}
            <tr class="row">
                <td>{$d.id}</td>
                <td>{$d.name}</td>
                <td>{$d.phone}</td>
                <td>{$d.sex}</td>
                <td>{$d.type ? '大订单客户' : '普通客户'}</td>
                <td data-id="{$d.id}" data-name="{$d.name}" data-phone="{$d.phone}" data-sex="{$d.sex}" data-type="{$d.type}">
                    <button class="btn btn-primary saveUser" type="button">修改</button>
                    <button class="btn btn-danger delUser" type="button">删除</button>
                </td>
            </tr>
            {/foreach}
            </tbody>
        </table>
    </div>
    <div class="text-center">
        {$data->render()}
    </div>
</div>

<!-- 删除确认模态框 -->
<div class="modal fade" id="delModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <form action="{:url('admin/User/delete')}" method="post">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-hidden="true">×
                    </button>
                    <h4 class="modal-title" id="myModalLabel">
                        删除确认
                    </h4>
                </div>
                <div class="modal-body">
                    确认删除:<strong id="determine"></strong>?
                    <input type="hidden" name="id" value="">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">关闭
                    </button>
                    <button type="submit" class="btn btn-primary">
                        确认
                    </button>
                </div>
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>

<!-- 新增用户模态框 -->
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <form action="{:url('admin/User/add')}" method="post" class="form-horizontal" role="form">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-hidden="true">×
                    </button>
                    <h4 class="modal-title" id="addModalLabel">
                        新增会员
                    </h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label for="addName" class="col-sm-2 control-label">名字</label>
                        <div class="col-sm-10">
                            <input type="text" name="name" class="form-control" id="addName" placeholder="请输入名字">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="addPhone" class="col-sm-2 control-label">电话号码</label>
                        <div class="col-sm-10">
                            <input type="text" name="phone" class="form-control" id="addPhone" placeholder="请输入电话号码">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="addPassword" class="col-sm-2 control-label">密码</label>
                        <div class="col-sm-10">
                            <input type="text" name="password" class="form-control" id="addPassword"
                                   placeholder="请输入密码">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="addSex" class="col-sm-2 control-label">性别</label>
                        <div class="col-sm-10">
                            <select id="addSex" name="sex" class="form-control">
                                <option value="男">男</option>
                                <option value="女">女</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="addType" class="col-sm-2 control-label">类别</label>
                        <div class="col-sm-10">
                            <select id="addType" name="type" class="form-control">
                                <option value="0">普通用户</option>
                                <option value="1">大订单客户</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">关闭
                    </button>
                    <button type="submit" class="btn btn-primary">
                        确认
                    </button>
                </div>
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>


<!-- 修改用户模态框 -->
<div class="modal fade" id="saveModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <form action="{:url('admin/User/update')}" method="post" class="form-horizontal" role="form">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-hidden="true">×
                    </button>
                    <h4 class="modal-title" id="saveModalLabel">
                        新增会员
                    </h4>
                </div>
                <div class="modal-body">
                    <input type="hidden" id="id" name="id" value="">
                    <div class="form-group">
                        <label for="saveName" class="col-sm-2 control-label">名字</label>
                        <div class="col-sm-10">
                            <input type="text" name="name" class="form-control" id="saveName" placeholder="请输入名字">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="savePhone" class="col-sm-2 control-label">电话号码</label>
                        <div class="col-sm-10">
                            <input type="text" name="phone" class="form-control" id="savePhone" placeholder="请输入电话号码">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="savePassword" class="col-sm-2 control-label">密码</label>
                        <div class="col-sm-10">
                            <input type="text" name="password" class="form-control" id="savePassword"
                                   placeholder="若不更新密码，请不要输入密码">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="saveSex" class="col-sm-2 control-label">性别</label>
                        <div class="col-sm-10">
                            <select id="saveSex" name="sex" class="form-control">
                                <option value="男">男</option>
                                <option value="女">女</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="saveType" class="col-sm-2 control-label">类别</label>
                        <div class="col-sm-10">
                            <select id="saveType" name="type" class="form-control">
                                <option value="0">普通用户</option>
                                <option value="1">大订单客户</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">关闭
                    </button>
                    <button type="submit" class="btn btn-primary">
                        确认
                    </button>
                </div>
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>
{/block}

{block name='js'}
<script>
    $(function () {
        $('#cm-menu-scroller > ul > li:nth-child(4)').addClass('active');

        $("[data-toggle='tooltip']").tooltip();
    });

    $('.delUser').click(function () {
        var id = $(this).parent().data('id');
        var name = $(this).parent().data('name');

        $('#determine').text(name);
        $('#determine').next().val(id);
        $('#delModal').modal();
    });

    $('.saveUser').click(function () {
        var id = $(this).parent().data('id');
        var name = $(this).parent().data('name');
        var phone = $(this).parent().data('phone');
        var pwd = $(this).parent().data('password');
        var sex = $(this).parent().data('sex');
        var type = $(this).parent().data('type');

        $('#id').val(id);
        $('#saveName').val(name);
        $('#savePhone').val(phone);
        $('#savePassword').val(pwd);
        $('#saveSex').val(sex);
        $('#saveType').val(type);

        $('#saveModal').modal();
    });

    $('#addUser').click(function () {

        $('#addModal').modal();
    });

</script>
{/block}